package rgbos.forum.persistance;

import java.util.Vector;

import rgbos.forum.domain.Post;
import rgbos.forum.domain.Topic;
import rgbos.forum.domain.User;

public class Persistance {
	PersImpl impl_;
	
	public Persistance(String type){
		create(type);
	}
	public void create(String type){
		if(type.equals("XML")){
			impl_ = new  XMLFacade();
		}
		else if(type.equals("SQL")){
			impl_ = new  SQLFacade();
		}
	}
	public void connect(){
		impl_.connect();
	}
	public void closeConnection(){
		impl_.closeConnection();
	}
	public void createNewTables(){
		impl_.createNewTables();
	}
	//Posts:
	public int saveNewPost(Post post,int topicId){
		return impl_.saveNewPost(post, topicId); 
	}
	public boolean modifyPost(Post post){
		return impl_.modifyPost(post);
	}
	public boolean modifyPostBody(int postId,String title,String body){
		return impl_.modifyPostBody(postId, title, body);
	}
	public boolean deletePost(int postId){
		return impl_.deletePost(postId);
	}
	public Post getPostById(int postId){
		return impl_.getPostById(postId);
	}
	public Vector<Post> getPosts(){
		return impl_.getPosts();
	}

	//Topics:
	public int saveNewTopic(Topic topic){
		return impl_.saveNewTopic(topic);
	}
	public boolean modifyTopic(Topic topic){
		return impl_.modifyTopic(topic);
	}
	public boolean deleteTopic(int topicId){
		return impl_.deleteTopic(topicId);
	}
	public Topic getTopicById(int topicId){
		return impl_.getTopicById(topicId);
	}
	public  Vector<Topic> getTopics(){
		return impl_.getTopics();
	}

	//Users:
	public boolean registerNewUser(User newUser){
		return impl_.registerNewUser(newUser);
	}
	public boolean logIn(String userName, String pass){
		return impl_.logIn(userName, pass);
	}
	public boolean modifyUserDetails(User user){
		return impl_.modifyUserDetails(user);
	}
	public boolean deleteUser(String username){
		return impl_.deleteUser(username);
	}
	public boolean setModerator(String username){
		return impl_.setModerator(username);
	}
	public boolean setAdmin(String username){
		return impl_.setAdmin(username);
	}
	public boolean checkExistUser(String username){
		return impl_.checkExistUser(username);
	}
	public boolean changePermission(String username, int value){
		return impl_.changePermission(username, value);
	}
	public boolean checkAdmin(String username){
		return impl_.checkAdmin(username);
	}
	public boolean checkModerator(String username){
		return impl_.checkModerator(username);
	}
	public Vector<User> getUsers(){
		return impl_.getUsers();
	}
	public Vector<String> getUsersName(){
		return impl_.getUsersName();
	}
	public Vector<User> getOnlineUsers(){
		return impl_.getOnlineUsers();
	}
	public void addViewCount(int topicId){
		impl_.addViewCount(topicId);
	}
	public boolean setOnlineBit(String userName, int onlineBit){
		return impl_.setOnlineBit(userName, onlineBit);
	}
	public int getOnlineBit(String userName){
		return impl_.getOnlineBit(userName);
	}
	public User getUserByName(String username){
		return impl_.getUserByName(username);
	}
	public void addCulumn(String columnName,String columnType){
		impl_.addCulumn(columnName, columnType);
	}
	public Vector<Post> getPostsByUser(String username){
		return impl_.getPostsByUser(username);
	}
	public String getEmailByName(String userName){
		return impl_.getEmailByName(userName);
	}
	
	//Users-Hours
	public void createUsersHours(){
		impl_.createUsersHours();
	}
	public boolean incHour(int hour){
		return impl_.incHour(hour);
	}
	public int[] getHourStats(){
		return impl_.getHourStats();
	}
	public Topic getTopicByPost(int id) {
		return impl_.getTopicByPost(id);
	}	
}
